package com.ruoyi.project.system.groupimg.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.groupimg.domain.GroupImg;
import com.ruoyi.project.system.groupimg.service.IGroupImgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 集团风采图片
 *
 * Created by Administrator.
 *
 * @autor LCL - 2020/8/3 - 16:41.
 */
@Controller
@RequestMapping("/system/img")
public class GroupImgController extends BaseController {

    private String prefix = "system/img";

    @Autowired
    private IGroupImgService groupImgService;

    @RequiresPermissions("system:img:view")
    @GetMapping()
    public String img()
    {
        return prefix + "/img";
    }

    /**
     * 查询集团风采 主图列表
     */
    @RequiresPermissions("system:img:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GroupImg groupImg)
    {
        startPage();
        List<GroupImg> list = groupImgService.selectGroupImgList(groupImg);
        return getDataTable(list);
    }

    /**
     * 导出集团风采 主图列表
     */
    @RequiresPermissions("system:img:export")
    @Log(title = "集团风采 主图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GroupImg groupImg)
    {
        List<GroupImg> list = groupImgService.selectGroupImgList(groupImg);
        ExcelUtil<GroupImg> util = new ExcelUtil<GroupImg>(GroupImg.class);
        return util.exportExcel(list, "img");
    }

    /**
     * 新增集团风采 主图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存集团风采 主图
     */
    @RequiresPermissions("system:img:add")
    @Log(title = "集团风采 主图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GroupImg groupImg)
    {
        return toAjax(groupImgService.insertGroupImg(groupImg));
    }

    /**
     * 修改集团风采 主图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GroupImg groupImg = groupImgService.selectGroupImgById(id);
        mmap.put("groupImg", groupImg);
        return prefix + "/edit";
    }

    /**
     * 修改保存集团风采 主图
     */
    @RequiresPermissions("system:img:edit")
    @Log(title = "集团风采 主图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GroupImg groupImg)
    {
        return toAjax(groupImgService.updateGroupImg(groupImg));
    }

    /**
     * 删除集团风采 主图
     */
    @RequiresPermissions("system:img:remove")
    @Log(title = "集团风采 主图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(groupImgService.deleteGroupImgByIds(ids));
    }

}
